<template>
  <div>
    <search-tt @reset="reset" @search='search' :disabled='searchDisabled' :typeInfo='typeInfo' :years='years' @statusChange='statusChange'></search-tt>
    <el-table v-loading='loading' height="500" v-infinite-scroll="load" :infinite-scroll-disabled='disabled' stripe border :data="examineList" infinite-scroll-delay='1000' style="width: 100%" row-key="menuId">
      <el-table-column label="序号" type="index" width="70" center></el-table-column>
      <el-table-column label="项目名称"  prop="title"></el-table-column>
      <el-table-column  label="开始时间"  prop="startTime" ></el-table-column>
      <el-table-column label="结束时间" prop="endTime"></el-table-column>
      <el-table-column  label="发布时间" prop="createTime" ></el-table-column>
      <!-- <el-table-column v-if="hasAuth('sys:project:taskNum')" label="审批总人数" prop="totalCount" width="100"></el-table-column>
      <el-table-column v-if="hasAuth('sys:project:taskNum')" label="已审批人数" prop="approveCount" width="100"></el-table-column>
      <el-table-column v-if="hasAuth('sys:project:taskNum')" label="未审批人数" prop="resultCount" width="100"></el-table-column>
      <el-table-column label="未提交人数" prop="noSubmitCount" width="100"></el-table-column> -->
      <el-table-column label="状态" prop="status" width="90"></el-table-column>
      <el-table-column label="操作" width="180"  fixed="right">
        <template slot-scope="scope">
          <el-button v-if="hasAuth('sys:examine')" type="text"  @click="$router.push('/home/resultlist?pId='+scope.row.id)">审批 </el-button>
          <el-button v-if="hasAuth('sys:examine')" type="text"  @click="$router.push('/home/unsubmitlist?pId='+scope.row.id)">查看未提交人员 </el-button>
        </template>
      </el-table-column>
      <template slot="empty">
        {{loading?'加载中':'暂无数据'}}
      </template>
    </el-table>
  </div>
</template>

<script>
  import searchTt from "@/components/searchTt.vue"
  export default{
    name:"examine",
    data(){
      return {
        examineList:[],
        typeInfo:{
          title:'',
          status:'',
          page:0,
          limit:10,
          year:''
        },
        total:0,
        flag:false,
        loading:false,
        years:[],
        searchDisabled:false
      }
    },
    components:{searchTt},
    methods:{
      async initExamineList(){
        this.loading=true
        if(this.flag){
          this.loading=false
          this.searchDisabled=false
          return
        }
         let result=await this.$get('/api/project/approve',this.typeInfo)
         this.loading=false
        this.flag=result.data.list.length<this.typeInfo.limit
        if(!result.code==200) return this.$message.error(result.msg)
        result.data.list.map(item=>item.status=item.status?'已完成':'未完成')
        this.examineList.push(...result.data.list)
        this.total=result.data.total
        this.searchDisabled=false
      },
      async initSel(){
        let result=await this.$get('/api/project/approve/years')
        if(result.code==200) {
          this.years=result.data
          this.typeInfo.year=result.data[0]
          this.typeInfo.page=1
          this.initExamineList()
        }
      },
      reset(){
        this.resetInfo()
        this.typeInfo.year=''
        this.typeInfo.title=''
        this.loading=true
        this.flag=false
        this.initExamineList()
      },
      load(){
        this.typeInfo.page++
        this.initExamineList()
      },
      resetInfo(){
        this.examineList=[]
        this.typeInfo.page=1
      },
      search(){
        this.resetInfo()
        this.searchDisabled=true
        this.flag=false
        this.initExamineList()
      },
      // 切换项目状态回调
      statusChange(){
        this.resetInfo()
        // this.typeInfo.year=val
        this.flag=false
        this.initExamineList()
      },
    },
    mounted(){
      this.initSel()
    },
    computed:{
      disabled(){
        return this.examineList.length!=this.total
      }
    }
  }
</script>

<style>
</style>
